package com.shop.servlet.comment;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.entity.Comment;
import com.shop.service.CommentService;
import com.shop.service.UserService;

/**
 * Servlet implementation class CommentAddcomServlet
 */
@WebServlet("/commentAdd")
public class CommentAddcomServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CommentAddcomServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String msg = "";
		CommentService CommentService = new CommentService();
		
		Comment cm = new Comment();
		String comment = request.getParameter("comment");
		String username = request.getParameter("username");
		Date time = new Date();
		cm.setComment(comment);
		cm.setUsername(username);
		cm.setTime(time);
		CommentService.addComment(cm);
		msg = "评论成功 ！";
		request.setAttribute("msg", msg);
		request.getRequestDispatcher("commentlist").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
